package com.jiaai.web.member;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.auth.model.AccessUser;
import com.jiaai.exception.ServerException;
import com.jiaai.filter.aop.TokenIntercept;
import com.jiaai.member.api.IWalletAPI;
import com.jiaai.member.model.VWalletHistorySearch;
import com.jiaai.util.ConstantUtils;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title WalletController
 * @since 2017/11/13
 */
@RequestMapping("/api/v1/wallet")
@RestController
public class WalletController  {
    @Reference
    private IWalletAPI walletAPI;


    @GetMapping("/my/{mId}")
    public Object findMyWallet(@PathVariable("mId") String mId)throws ServerException {

        return RestResultGenerator.genSuccessResult(walletAPI.findBymId(mId));
    }


    @GetMapping("/findHistory")
    @TokenIntercept(checkVisitor = true)
    public  Object findWalletHistory(@SessionAttribute(ConstantUtils.ACCESS_USER) AccessUser accessUser, VWalletHistorySearch search)throws  ServerException{
        search.setmId(accessUser.getUserId());
        return RestResultGenerator.genSuccessResult(walletAPI.findByWalletHistory(search));
    }

    @GetMapping("/tx")
    @TokenIntercept(checkVisitor = true)
    public  Object tx(@SessionAttribute(ConstantUtils.ACCESS_USER)AccessUser user,Integer glod)throws  ServerException{
        walletAPI.tx(user.getUserId(),glod);
        return RestResultGenerator.genSuccessResult();
    }

}
